var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var root = ui("$");
var http = require("helper/http");
var mallUrl = require("url/mall");

var shopId = null;
var quanPayRate = null;
var quanPayRateNew = "";
var seekBar = ui("seekBar");
//获取上一个页面传入的参数
page.on("loaded", function(){
	var params = page.getData();
	shopId = params.id;
	quanPayRate = params.quanPayRate;
	ui("labelRate").text = quanPayRate*100+"%";
	seekBar.progress = quanPayRate*100;
});

//返回键
page.on("back", function() {
    app.closePage();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
ui(addheader + ".labelTitle").text = "修改圈币结算比例";
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage();
});

//保存
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "保存";
headerRight_lableNext.visible = true;
headerRight.on("touch", function() {
	if(quanPayRateNew>1 || quanPayRateNew<0){
		nf.toast("圈币结算比例必须在0到1之间");
		return;
	}
	
	quanPayRateNew = Math.round(quanPayRateNew*100)/100;
	submit();
});

function submit(){
	var params = {
		id:shopId,
		quanPayRate:quanPayRateNew
	};
	http.post(mallUrl.url.shop.updateQuanPayRate, params, function(data) {
		app.fire("fireShopUpdate",{"quanPayRate":quanPayRateNew});
		app.closePage();
	});
};

ui("seekBar").on("progressChanged", function(data, e) {
	var curProgress = Math.round(seekBar.progress);
	ui("labelRate").text = curProgress+"%";
	quanPayRateNew = curProgress/100;
	deviceone.print(quanPayRateNew, "quanPayRateNew")
})


var linearLayout_main = ui("do_LinearLayout_main");

var addLine = linearLayout_main.add("line", "source://view/reuse/form/line.ui",0,0);
ui("line").refreshData();
/** -------------------add UI end ---------------------------**/
